#!/bin/sh

. /lib/functions/network.sh

[ "$ACTION" = "ifup" -a "$INTERFACE" = "wan" ] || exit 0

network_get_ipaddr wanip wan

lanip=$(uci get network.lan.ipaddr)
netmask=$(uci get network.lan.netmask)

eval "$(ipcalc.sh "$lanip" $netmask)"
lannet=$NETWORK

eval "$(ipcalc.sh "$wanip" $netmask)"
wannet=$NETWORK

if [ "$lannet" = "$wannet" ];then
	lanip=$(echo $lanip | awk -F. '{print $1"."$2"."$3+1"."$4}')
	uci set network.lan.ipaddr=$lanip
	reboot
fi